package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.BuyMedicines;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Registered;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.BuyMedicinesService;
import com.woniuxy.propertyjava.service.RegisteredService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class BuyMedicinesController {

    @Resource
    private BuyMedicinesService buyMedicinesService;

    //路径变量参数
    //条件查询+分页
    @PostMapping("/buyMediciness/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<BuyMedicines>>
         getqueryAllMedicines(@PathVariable("pageIndex") int pageIndex,
                             @PathVariable("pageSize") int pageSize,
                             @RequestBody BuyMedicines buyMedicines){
        System.out.println("查询条件："+buyMedicines);
        System.out.println("pageIndex："+pageIndex);
        System.out.println("pageSize："+pageSize);
        PageBean<BuyMedicines> pageBean= buyMedicinesService.getqueryAllMedicines(buyMedicines,pageIndex,pageSize);

        ResponseResult<PageBean<BuyMedicines>> responseResult=
                new ResponseResult<>(200,"ok",pageBean);
        return responseResult;
    }

    //添加人员
    @PostMapping("/buyMediciness")
    public ResponseResult addMedicines(@RequestBody BuyMedicines buyMedicines){
        System.out.println("添加人员"+buyMedicines);
        buyMedicinesService.getinsert(buyMedicines);
        return new ResponseResult<>(200, "添加成功", null);
    }

    //修改人员
    @PutMapping("/buyMediciness")
    public ResponseResult modifyMedicines(@RequestBody BuyMedicines buyMedicines){
        System.out.println("修改人员"+buyMedicines);
        buyMedicinesService.getupdate(buyMedicines);
        return new ResponseResult<>(200, "修改成功", null);
    }

    //删除人员
    @DeleteMapping("/buyMediciness/{bmid}")
    public ResponseResult removeMedicines(@PathVariable("bmid") int bmid){
        System.out.println("删除人员"+bmid);
        buyMedicinesService.getdeleteById(bmid);
        return new ResponseResult<>(200, "删除成功", null);
    }



}
